<#assign ctx = request.contextPath />
<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />
    <title>绑定客户经理</title>
    <link href="${ctx}/assets/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="${ctx}/assets/css/weixing.css" rel="stylesheet"/>
    <link href="${ctx}/assets/css/sco.message.css" rel="stylesheet"/>
  </head>
  <body>
  	<form id="submit_form" action="${ctx}/wx/v1/ConsumerManager/bindPost" method="post">
  		<input type="hidden" name="wxuser" value="${wxuser}">
		
		<div class="input-group" style="margin:10px 15px 0px 15px;">
	      <input id="phone" name="phone" type="text" class="form-control" placeholder="输入手机号码" >
	      <span class="input-group-btn">
	        <button id="getCode" class="btn btn-default" type="button" disable="false">获取验证码</button>
	      </span>
	    </div>
	    
		<div class="form-group" style="margin:10px 15px 20px 15px;">
		    <input id="code" name="code" class="form-control floating-label" type="text" placeholder="请输入验证码"  >
		</div>
		
		<div class="denglu">
			<button id="submit_button" type="submit" class="btn btn-default btn-block" style="color:#ffffff">提交</button>
		</div>
	</form>
	
    <script src="${ctx}/assets/js/jquery-1.11.0.min.js"></script>
    <script src="${ctx}/assets/js/bootstrap.min.js"></script>
    <script src="${ctx}/assets/js/sco.message.js"></script>
    <script type="text/javascript">
		
		$(function () {
		
			//提交
			$("#submit_form").submit(function(){
			
				$("#submit_button").attr("disabled",true);
				
				var phone = $("#phone").val();
				if (phone == "" || phone.length != 11){
					$.scojs_message("请填写正确的电话号码。", $.scojs_message.TYPE_ERROR);
					$("#submit_button").attr("disabled",false);
					return false;
				}
				
				var code = $("#code").val();
				if (code == ""){
					$.scojs_message("请填写验证码。", $.scojs_message.TYPE_ERROR);
					$("#submit_button").attr("disabled",false);
					return false;
				}
				
			   	return true;
			});
			
			$("#getCode").click(function(){
				var phone = $("#phone").val();
				if (phone == "" || phone.length != 11){
					$.scojs_message("请填写正确的手机号码！", $.scojs_message.TYPE_ERROR);
					return;
				}
				
				if($("#getCode").attr("disable")=="false"){
					$("#getCode").attr("disable",true);
					$.get('${ctx}/wx/v1/ConsumerManager/smsQrCode',{'phone':phone},function(result){
						if(result.success){
							$.scojs_message("验证码已发送成功", $.scojs_message.TYPE_OK);
							smsOverTime(120);
						}
						else{
							if(result.errorcode=="0"){
								smsOverTime(result.object);
							}
							else if(result.errorcode=="1"){
								$.scojs_message("短信发送失败，请稍后再试", $.scojs_message.TYPE_ERROR);
								$("#getCode").attr("disable",false);
							}
						}
					});
				}
			});
			
		});
		
		function smsOverTime(t){
			var howlong=t;
			
			howlong--;
			$("#getCode").html(howlong);
			
			var timeID=setTimeout("smsOverTime("+howlong+")",1000);
			if(howlong<=0){
				clearTimeout(timeID);
				$("#getCode").html("获取验证码");
				$("#getCode").attr("disable",false);
			}
			
		}
			
	</script>
  </body>
</html>
